//
//  MAStaffCell.m
//  meiang_edu
//
//  Created by hfcb on 2018/8/1.
//  Copyright © 2018年 com.meiang.meiang_edu. All rights reserved.
//

#import "MAStaffCell.h"
#import "MAStaffModel.h"
#import "MATeacherModel.h"
#import "MAPhotoListModel.h"

#define StaffCell @"StaffCell"

@interface MAStaffCell ()
@property (weak, nonatomic) IBOutlet UIView *containerView;
@property (weak, nonatomic) IBOutlet UIImageView *iconView;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *detailLabel;
@property (weak, nonatomic) IBOutlet UIImageView *sexIcon;

@property (weak, nonatomic) IBOutlet UIImageView *callIcon;
@end

@implementation MAStaffCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.containerView.layer.cornerRadius = 4;
    self.containerView.layer.masksToBounds = YES;
    
    self.iconView.layer.cornerRadius = 20;
    self.iconView.layer.masksToBounds = YES;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil] lastObject];
    }
    return self;
}

+ (instancetype)cellWithTableView:(UITableView *)tableView {
    
    MAStaffCell *cell = [tableView dequeueReusableCellWithIdentifier:StaffCell];
    if (cell == nil) {
        cell = [[MAStaffCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:StaffCell];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
+ (instancetype)cellWithTableView:(UITableView *)tableView hasCall:(BOOL)hasCall {
    
    MAStaffCell *cell = [tableView dequeueReusableCellWithIdentifier:StaffCell];
    if (cell == nil) {
        cell = [[MAStaffCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:StaffCell];
    }
    cell.callIcon.hidden = !hasCall;
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (void)setModel:(MAStaffModel *)model {
    _model = model;
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",IMG_OSS,model.ps_id]] placeholderImage:[UIImage imageNamed:@"homepage_navigationbar_picture"]];
    
    self.sexIcon.image = [model.cgender isEqualToString:@"男"] ? [UIImage imageNamed:@"mansymbol_logo"] : [UIImage imageNamed:@"womansymbol_logo"];
    self.nameLabel.text = model.cname;
    if (self.cellStyle == MAStaffCellStyleMgrList) {
        self.detailLabel.text = model.us_type;
    } else {
        self.detailLabel.text = [NSString stringWithFormat:@"%@",model.ustype];
    }
    model.cellHeight = 64;
}

- (void)setTeacherModel:(MATeacherModel *)teacherModel {
    _teacherModel = teacherModel;
    
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",IMG_OSS,teacherModel.ps_id]] placeholderImage:[UIImage imageNamed:@"homepage_navigationbar_picture"]];
    
//    self.sexIcon.image = [teacherModel. isEqualToString:@"男"] ? [UIImage imageNamed:@"mansymbol_logo"] : [UIImage imageNamed:@"womansymbol_logo"];
    self.nameLabel.text = teacherModel.tename;
    self.detailLabel.text = teacherModel.tetype;
    teacherModel.cellHeight = 64;
}

- (void)setPhotoListModel:(MAPhotoListModel *)photoListModel {
    _photoListModel = photoListModel;
    
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",IMG_OSS,photoListModel.ps_id]] placeholderImage:[UIImage imageNamed:@"homepage_navigationbar_picture"]];
    
    self.nameLabel.text = photoListModel.cname;
    self.detailLabel.text = photoListModel.ustype;
    photoListModel.cellHeight = 64;
}

@end
